<template>
	<view class="tabbar">
		<view class="tabbar-fixed">
			<view class="tabbar-content">
				<view class="tabbar-item"
				 :class="{active: value == index}"
					@click="clickTab(index)" v-for="(item, index) in tabList" :key="index">
					<text :class="['iconfont', item.icon]"/>
					<view class="tabbar-name">{{item.name}}</view>
				</view>
			</view>
			<u-safe-bottom/>
		</view>
		<view class="tabbar-place"/>
		<u-safe-bottom/>
	</view>
</template>

<script>
	export default {
		name:"tabbar",
		props: {
			safeAreaInsetBottom: {
				type: Boolean,
				default: true
			},
			placeholder: {
				type: Boolean,
				default: true
			}
		},
		data() {
			return {
				value: 0,
				tabList: [{
						name: '首页',
						icon: 'icon-home',
						path: '/pages/index/index'
					},
					{
						name: '选材',
						icon: 'icon-caidan',
						path: '/pages/materials/materials'
					},
					{
						name: '案例',
						icon: 'icon-anli',
						path: '/pages/case/case'
					},{
						name: '成品',
						icon: 'icon-vip-one',
						path: '/pages/product/product'
					},
					{
						name: '我的',
						icon: 'icon-my',
						path: '/pages/my/my'
					},
				],
			};
		},
		computed: {
			currPage() {
				let currentPath = getCurrentPages()
				return currentPath[currentPath.length - 1].route.replaceAll('/', '')
			}
		},
		methods: {
			clickTab(index) {
				let toPath = this.tabList[index].path
				if (toPath.replaceAll('/', '') == this.currPage) return
				uni.switchTab({
					url: this.tabList[index].path
				})
			},
		},
		created() {
			this.value = this.tabList.findIndex(item => item.path.replaceAll('/', '') == this.currPage)
		}
	}
</script>

<style lang="scss" scoped>
.tabbar {
	.tabbar-fixed {
		position: fixed;
		bottom: 0;
		background-color: #252525;
		width: 100%;
    z-index: 999;
	}
	.tabbar-place {
		height: 50px;
	}
	.tabbar-content {
		height: 50px;
		display: flex;
		justify-content: center;
		align-items: center;
		.tabbar-item {
			flex: 1;
			text-align: center;
			color: #999;
			.iconfont {
				font-size: 40rpx;
			}
			.tabbar-name {
				font-size: 28rpx;;
			}
			&.active {
				color: #fff;
			}
		}
	}
}
</style>